-- =====================================================================
-- {{{ s_widgets
-- =====================================================================
-- styling
wi_progressbar = {}
wi_progressbar["width"] = 5
wi_progressbar["height"] = 19
wi_progressbar["vertical"] = true
wi_progressbar["background_color"] = "peru"
wi_progressbar["border_color"] = "black"
wi_progressbar["color"] = "#008800"
--wi_progressbar["gradient_colors"] = ({"#00ff00", "#bb5500", "#ff0000"})

wi_graph = {}
wi_graph["width"] = 50
wi_graph["height"] = 19
wi_graph["background_color"] = "peru"
wi_graph["border_color"] = "black"
wi_graph["color"] = "#008800"
-- wi_graph["gradient_colors"] = ({"#00ff00", "#bb5500", "#ff0000"})

-- top wiboxes
wibox_top = {}

-- bottom wiboxes
wibox_bottom = {}

-- right wiboxes
wibox_right = {}

-- textclock
wi_textclock = awful.widget.textclock({ align = "right" }) 

-- systrays
wi_systray = widget({ type = "systray" })

-- layoutboxes
wi_layoutbox = {}

-- taglists
wi_taglist = {}
wi_taglist.buttons = awful.util.table.join(
                     awful.button({ }, 1, awful.tag.viewonly)
                     )

-- divider
wi_divider = widget({ type = "textbox" })
wi_divider.text = " | "

-- counter widget
wi_counter = widget({ type = "textbox" })
wi_counter.text = 0;

-- tasklists
wi_tasklist = {}
wi_tasklist.buttons = awful.util.table.join(
                     awful.button({ }, 1, function (c)
                                              if not c:isvisible() then
                                                  awful.tag.viewonly(c:tags()[1])
                                              end
                                              client.focus = c
                                              c:raise()
                                          end),
                     awful.button({ }, 3, function ()
                                              if instance then
                                                  instance:hide()
                                                  instance = nil
                                              else
                                                  instance = awful.menu.clients({ width=250 })
                                              end
                                          end)
)

-- memory widgets
wi_ram_progressbar = awful.widget.progressbar()
wi_ram_progressbar:set_width(wi_progressbar["width"])
wi_ram_progressbar:set_height(wi_progressbar["height"])
wi_ram_progressbar:set_vertical(wi_progressbar["vertical"])
wi_ram_progressbar:set_background_color(wi_progressbar["background_color"])
wi_ram_progressbar:set_border_color(wi_progressbar["border_color"])
wi_ram_progressbar:set_color(wi_progressbar["color"])
wi_ram_progressbar:set_gradient_colors(wi_progressbar["gradient_colors"])
vicious.register(wi_ram_progressbar, vicious.widgets.mem, "$1", 13)

wi_swp_progressbar = awful.widget.progressbar()
wi_swp_progressbar:set_width(wi_progressbar["width"])
wi_swp_progressbar:set_height(wi_progressbar["height"])
wi_swp_progressbar:set_vertical(wi_progressbar["vertical"])
wi_swp_progressbar:set_background_color(wi_progressbar["background_color"])
wi_swp_progressbar:set_border_color(wi_progressbar["border_color"])
wi_swp_progressbar:set_color(wi_progressbar["color"])
wi_swp_progressbar:set_gradient_colors(wi_progressbar["gradient_colors"])
vicious.register(wi_swp_progressbar, vicious.widgets.mem, "$5", 13)

-- cpu widgets
wi_cpu_graph0 = awful.widget.graph()
wi_cpu_graph0:set_width(wi_graph["width"])
wi_cpu_graph0:set_height(wi_graph["height"])
wi_cpu_graph0:set_background_color(wi_graph["background_color"])
wi_cpu_graph0:set_color(wi_graph["color"])
wi_cpu_graph0:set_gradient_colors(wi_graph["gradient_colors"])
wi_cpu_graph0:set_border_color(wi_graph["border_color"])
vicious.register(wi_cpu_graph0, vicious.widgets.cpu, "$2")

wi_cpu_graph1 = awful.widget.graph()
wi_cpu_graph1:set_width(wi_graph["width"])
wi_cpu_graph1:set_height(wi_graph["height"])
wi_cpu_graph1:set_background_color(wi_graph["background_color"])
wi_cpu_graph1:set_color(wi_graph["color"])
wi_cpu_graph1:set_gradient_colors(wi_graph["gradient_colors"])
wi_cpu_graph1:set_border_color(wi_graph["border_color"])
vicious.register(wi_cpu_graph1, vicious.widgets.cpu, "$3")

-- battary widgets
wi_bat = widget({ type = "textbox" })
vicious.register(wi_bat, vicious.widgets.bat, "$1$3", 60, "BAT0")

wi_bat_progressbar = awful.widget.progressbar()
wi_bat_progressbar:set_width(wi_progressbar["width"])
wi_bat_progressbar:set_height(wi_progressbar["height"])
wi_bat_progressbar:set_vertical(wi_progressbar["vertical"])
wi_bat_progressbar:set_background_color(wi_progressbar["background_color"])
wi_bat_progressbar:set_border_color(wi_progressbar["border_color"])
wi_bat_progressbar:set_color(wi_progressbar["color"])
wi_bat_progressbar:set_gradient_colors(wi_progressbar["gradient_colors"])
vicious.register(wi_bat_progressbar, vicious.widgets.bat, "$2", 60, "BAT0")

-- thermal widgets
-- divider
wi_T = widget({ type = "textbox" })
wi_T.text = "T"

wi_thermal_sys_progressbar = awful.widget.progressbar()
wi_thermal_sys_progressbar:set_width(wi_progressbar["width"])
wi_thermal_sys_progressbar:set_height(wi_progressbar["height"])
wi_thermal_sys_progressbar:set_vertical(wi_progressbar["vertical"])
wi_thermal_sys_progressbar:set_background_color(wi_progressbar["background_color"])
wi_thermal_sys_progressbar:set_border_color(wi_progressbar["border_color"])
wi_thermal_sys_progressbar:set_color(wi_progressbar["color"])
wi_thermal_sys_progressbar:set_gradient_colors(wi_progressbar["gradient_colors"])
vicious.register(wi_thermal_sys_progressbar, vicious.widgets.thermal, "$1", 30, "thermal_zone0")

wi_thermal_disk_progressbar = awful.widget.progressbar()
wi_thermal_disk_progressbar:set_width(wi_progressbar["width"])
wi_thermal_disk_progressbar:set_height(wi_progressbar["height"])
wi_thermal_disk_progressbar:set_vertical(wi_progressbar["vertical"])
wi_thermal_disk_progressbar:set_background_color(wi_progressbar["background_color"])
wi_thermal_disk_progressbar:set_border_color(wi_progressbar["border_color"])
wi_thermal_disk_progressbar:set_color(wi_progressbar["color"])
wi_thermal_disk_progressbar:set_gradient_colors(wi_progressbar["gradient_colors"])
vicious.register(wi_thermal_disk_progressbar, vicious.widgets.hddtemp, "${/dev/sda}", 30)

-- network widgets
wi_net = widget({ type = "textbox" })
vicious.register(wi_net, vicious.widgets.net, "(D${eth0 down_kb} U${eth0 up_kb})/", 2) 

wi_wnet = widget({ type = "textbox" })
vicious.register(wi_wnet, vicious.widgets.net, "(D${wlan0 down_kb} U${wlan0 up_kb} ", 2) 

wi_wifi = widget({ type = "textbox" })
vicious.register(wi_wifi, vicious.widgets.wifi, "ssid:${ssid}) ", 10, "wlan0") 

-- mpd widgets
wi_mpd = widget({ type = "textbox" })
vicious.register(wi_mpd, vicious.widgets.mpd, "(${volume}%)(${state}) ${Artist} - ${Album} - ${Title}", 2) 
 
-- system info widgets
wi_os = widget({ type = "textbox" })
vicious.register(wi_os, vicious.widgets.os, "$1-$2 ", 600) 

wi_upd = widget({ type = "textbox" })
vicious.register(wi_upd, vicious.widgets.pkg, "($1) | ", 60, "Arch") 


-- weather widget
-- UKKG
-- wi_weather = widget({ type = "textbox" })
-- vicious.register(wi_weather, vicious.widgets.weather, "${city}: ${windkmh}km/h ${weather} ${tempc}C | ", 3600, "UKLI") 


-- per-screen widget stuff
for s = 1, screen.count() do
    -- one layoutbox per screen.
    wi_layoutbox[s] = awful.widget.layoutbox(s)
    -- one taglist widget per screen
    wi_taglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, wi_taglist.buttons)

    -- one tasklist widget per screen
    wi_tasklist[s] = awful.widget.tasklist(function(c)
                                              return awful.widget.tasklist.label.currenttags(c, s)
                                          end, wi_tasklist.buttons)

    -- Create the wibox
    wibox_top[s] = awful.wibox({ position = "top", screen = s })
    wibox_bottom[s] = awful.wibox({ position = "bottom", screen = s })
    wibox_right[s] = awful.wibox({ position = "right", screen = s })
    -- Add widgets to the wibox - order matters
    -- top wibox
    wibox_top[s].widgets = {
        {
            wi_taglist[s],
            layout = awful.widget.layout.horizontal.leftright
        },
        wi_layoutbox[s],
        wi_textclock,
        s == 1 and wi_systray or nil,
        wi_tasklist[s],
        layout = awful.widget.layout.horizontal.rightleft
    }
    -- bottom wibox
    wibox_bottom[s].widgets = {
        {
        wi_swp_progressbar.widget,
        wi_cpu_graph1.widget,
        wi_cpu_graph0.widget,
        wi_ram_progressbar.widget,
        wi_bat,
        wi_bat_progressbar.widget,
        wi_T,
        wi_thermal_disk_progressbar.widget,
        wi_thermal_sys_progressbar.widget,
        wi_wifi,
        wi_wnet,
        wi_net,
        layout = awful.widget.layout.horizontal.rightleft
        },
        wi_os,
        wi_upd,
--        wi_weather,
        wi_mpd,
        layout = awful.widget.layout.horizontal.leftright}
    wibox_right[s].widgets = {
        wi_counter,
    }
 end
-- }}}
